package com.wzy.service.impl;

import com.wzy.dao.ChildDao;
import com.wzy.pojo.Child;
import com.wzy.service.ChildService;
import com.wzy.service.ExternalPopulationService;
import com.wzy.utils.Utils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("childService")
public class ChildServiceImpl implements ChildService {
    @Autowired
    private ExternalPopulationService externalPopulationService;

    SqlSession sqlSession = Utils.getSqlSession();
    ChildDao childDao =sqlSession.getMapper(ChildDao.class);

    @Override
    public List<Child> findAllChild() {
        return childDao.findAllChild();
    }

    @Override
    public Child findChild(String ID) {
        Child child = childDao.findChild(ID);
        System.out.println(child);
        return child;
    }

    @Override
    public boolean addChild(Child child) {
        if(externalPopulationService.findExternalPopulation(child.getID_number())!=null) {
            childDao.addChild(child);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public void deleteChild(String ID) {
        System.out.println("delete Success");
        childDao.deleteChild(ID);
    }

    @Override
    public void updateChild(Child c) {
        System.out.println("update Success");
        childDao.updateChild(c);

    }
}
